<?php

namespace App\Http\Controllers\admin\defaults;

use App\Helpers\commonFuc;
use App\Models\Admin;


use App\Models\AdminAuthRule;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class AuthruleController extends Controller
{
    private $tpview='admin.defaults.auth_rule.';
    private $thisModel;
    private $thisRequest;

    function __construct(Request $thisRequest)
    {
        $this->thisModel = DB::table('admin_auth_rule');
        $this->thisRequest = $thisRequest;
    }



    function lists(){
        return view($this->tpview.'lists');

    }

    function editbutton(){
        return view($this->tpview.'editbutton');

    }
    function edit(){
        return view($this->tpview.'edit');

    }
    function save(){
        $id = $this->thisRequest->post('id');
        $input=($this->thisRequest->all());
        if($id>0){
            $data = $this->thisModel->where('id',$id)->update($input);
            return commonFuc::data_reture_json_exit($data,200,'修改成功');

        }else{
            unset($input['id']);
            $input['title'] = '新建为命名';
            $input['ismenu'] = 0;
            $data = $this->thisModel->insertGetId($input);
            $data = $this->thisModel->find($data);
            return commonFuc::data_reture_json_exit($data,200,'新增完成');

        }

    }
    function del(){
        $id = $this->thisRequest->post('ids');

        $data = $this->thisModel->where('id',$id)->orWhere('pid',$id)->delete();

        return commonFuc::data_reture_json_exit($data,200,'删除成功');

    }

    function lists_json(){

        $adminmenus=AdminAuthRule::getMeun();
        $adminmenus=[['title'=>"权限菜单规则",'spread'=>true,'id'=>0,'children'=>$adminmenus]];

        return commonFuc::data_reture_json_exit($adminmenus);
    }


}
